package com.laobiao.file_netty_lib.content;


import java.util.logging.Level;

import io.netty.util.internal.ConcurrentSet;

public class FileContentApplication {
	/**
	 * 系统最近定义的一个任务组编号
	 */
	private static int lastBusinessNumber=0;

	/**
	 * 当前正在使用的任务组
	 */
	private final static ConcurrentSet<Integer> currBusinessNumbers=new ConcurrentSet<Integer>();
	
	/**
	 * 当前系统运行时的日志级别
	 */
	private static Level loggerLevel=Level.INFO;
	
	public static void setContentLoggerLevel(Level loggerLevel) {
		FileContentApplication.loggerLevel=loggerLevel;
	}
	
	

	public static Level getContentLoggerLevel() {
		return loggerLevel;
	}



	/**
	 * 生成全局业务组编号
	 * @return
	 */
	public synchronized static int getLastBusinessNumber() {
		long forSize=0;
		for(int x=lastBusinessNumber;x<Integer.MAX_VALUE;x++) {
			if(!currBusinessNumbers.contains(x)) {
				lastBusinessNumber=x;
				currBusinessNumbers.add(x);
				return lastBusinessNumber;
			}
			if(x+1==Integer.MAX_VALUE) {
				x=0;
			}
			forSize++;
			if(forSize==Integer.MAX_VALUE) {
				break;
			}
		}
		return -1;
	}
	
	/**
	 * 清理业务组编号缓存
	 * @param number
	 */
	public static void clearBusinessNumber(int number) {
		currBusinessNumbers.remove(number);
	}
	
	
}
